﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WyUnity.Data.Query;
using WyUnity.Data.TableMapper;

namespace DAL_13_0
{

    public class v_ICItemInfo : ViewBase<v_ICItemInfo>
    {
        [Map]
        public string Number { get; set; }
        [Map]
        public string Name { get; set; }
        [Map]
        public string BaseUnitName { get; set; }
        [Map]
        public decimal Coefficient { get; set; }
        [Map]
        public string PackageUnitName { get; set; }
        [Map]
        public string Barcode { get; set; }
        [Map]
        public string Model { get; set; }
        [Map]
        public String DefaultLoc { get; set; }
        [Map]
        public decimal Length { get; set; }
        [Map]
        public decimal Width { get; set; }
        [Map]
        public decimal Height { get; set; }
        [Map]
        public Decimal Weight { get; set; }
        [Map]
        public String Type1_Number { get; set; }
        [Map]
        public String Type1_Name { get; set; }
        [Map]
        public String Type2_Number { get; set; }
        [Map]
        public string Type2_Name { get; set; }
        [Map]
        public String MProperty { get; set; }
        [Map]
        public Decimal PackageQty_On_Pallet { get; set; }

        public override string GetSQLClip()
        {
            return @"
select ic.FNumber Number,ic.FName Name,ic.FModel Model
,ic.FDefaultLoc DefaultLocID,
ic.FLength Length,ic.FWidth Width,ic.FHeight Height
,u2.FCoefficient Coefficient,u2.FName PackageUnitName
,u1.FName BaseUnitName
,u3.FCoefficient Weight
,ic.F_103 Barcode
,stock.FNumber DefaultLoc
,mclass.FName MProperty
,mtype.FID Type1_Number,mtype.FName Type1_Name
,mtype2.FNumber Type2_Number,mtype2.FName Type2_Name
,case
	when isnull(u2.FCoefficient,0)=0 then 0
	else isnull(u4.FCoefficient,0)/isnull(u2.FCoefficient,0) end PackageQty_On_Pallet
from t_ICItem ic
left join t_MeasureUnit u1 on ic.FUnitID=u1.FItemID
left join t_MeasureUnit u2 on ic.F_102=u2.FItemID
left join t_MeasureUnit u3 on ic.FMaund=u3.FItemID
left join t_Stock stock on ic.FDefaultLoc=stock.FItemID
left join t_SubMessage mclass on ic.FErpClsID=mclass.FInterID
left join t_SubMessage mtype on ic.F_104=mtype.FInterID
left join t_Item mtype2 on ic.F_106=mtype2.FItemID
left join t_MeasureUnit u4 on ic.FUnitGroupID=u4.FUnitGroupID and u4.FName in('笼','托')

";
        }

        public static FieldBase pBarcode = new Field<v_ICItemInfo>(p => p.Barcode);
        public static FieldBase pNumber = new Field<v_ICItemInfo>(p => p.Number);
    }
}
